package com.my.service.impl;

import com.my.common.BaseDao;
import com.my.entity.User;
import com.my.service.IUserService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.Future;

/**
 * Created by wt on 2017/12/4.
 */
@Service
@Transactional(transactionManager = "betaTransactionManager", readOnly = false, propagation = Propagation.REQUIRED)
public class UserServiceImpl implements IUserService {
    @Autowired
    private BaseDao betaBaseDao;

//    @Override
//    public List<User> getUsers() {
//        return betaBaseDao.selectList("UserMapper.getUsers");
//    }

    @Override
    @Async
    public Future<List<User>> getUsers() {
        List<User> userList = betaBaseDao.selectList("UserMapper.getUsers");
        System.out.println("size：" + userList.size());

        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("service");
        return new AsyncResult<List<User>>(userList);
    }

    @Override
    public User getUser(Integer id) {
        return betaBaseDao.selectOne("UserMapper.getUser", id);
    }
}
